package com.ian.controller;

import com.common.util.ResultMsg;
import com.ian.pojo.PerFeedback;
import com.ian.service.PerFeedbackService;
import com.ian.service.PerUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户反馈
 *
 * @Author IanZy
 * @Date 2020/6/18
 */
@Api("用户反馈相关API")
@RestController
public class PerFeedBackController {
    @Autowired
    PerUserService perUserService;

    @Autowired
    PerFeedbackService perFeedbackService;

    /**
     * 客服反馈
     *
     * @Author IanZy
     * @Date 2020/6/20
     */
    @ApiOperation("用户反馈")
    @PostMapping(value = "/userFeedback", produces = "application/json;charset=UTF-8")
    public ResultMsg userFeedback(@RequestParam("mobile") String mobile, @RequestParam("details") String details) {
        try {
            int userId = perUserService.findByTel(mobile).getPerUserId();
            PerFeedback perFeedback = new PerFeedback();
            perFeedback.setPerUserId(userId);
            perFeedback.setPerFeedbackDetails(details);
            perFeedback.setPerUserTel(mobile);
            perFeedbackService.insert(perFeedback);
            return ResultMsg.success("反馈成功~", mobile);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMsg.failed("反馈失败");
        }
    }
}
